package com.lyfx.ly.controller;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.lyfx.ly.vo.StudyStepVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lyfx.ly.entity.StudyStepEntity;
import com.lyfx.ly.service.StudyStepService;
import com.lyfx.common.utils.PageUtils;
import com.lyfx.common.utils.R;



/**
 * **课程具体学习步骤**
 *
 * @author lsy
 * @email lsy@gmail.com
 * @date 2020-07-11 17:57:41
 */
@RestController
@RequestMapping("ly/studystep")
public class StudyStepController {
    @Autowired
    private StudyStepService studyStepService;

    /**
     * 返回对应课程的 树形菜单
     */
    @RequestMapping("/list/tree/{courseId}")
   // @RequiresPermissions("ly:studystep:list")
    public R list(@PathVariable("courseId") Long courseId){
        List<StudyStepVo> data = studyStepService.listWithTree(courseId);

        return R.ok().put("data", data);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{stepId}")
   // @RequiresPermissions("ly:studystep:info")
    public R info(@PathVariable("stepId") Long stepId){
		StudyStepEntity studyStep = studyStepService.getById(stepId);

        return R.ok().put("data", studyStep);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
   // @RequiresPermissions("ly:studystep:save")
    public R save(@RequestBody StudyStepEntity studyStep){
		studyStepService.save(studyStep);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("ly:studystep:update")
    public R update(@RequestBody StudyStepEntity studyStep){
		studyStepService.updateById(studyStep);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update/sort")
    // @RequiresPermissions("ly:studystep:update")
    public R updateSort(@RequestBody StudyStepEntity[] studyStep){
        studyStepService.updateBatchById(Arrays.asList(studyStep));
        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("ly:studystep:delete")
    public R delete(@RequestBody Long[] stepIds){
//		studyStepService.removeByIds(Arrays.asList(stepIds));
        studyStepService.removeMenusByIds(Arrays.asList(stepIds));
        return R.ok();
    }

}
